<script setup>
import HomePanel from "./HomePanel.vue";
import { getClickApi } from "@/apis/home";

const props = defineProps({
  productList:{
    type:Array,
    default:() => []
  }
})


const getClick = async (id) => {
  console.log("点击了", id);
  await getClickApi(id);
};

</script>

<template>
  <HomePanel title="商品搜索" subTitle="精准匹配">
    <!-- 下面是插槽主体内容模版 -->
    <ul class="goods-list">
      <li
        v-for="item in productList"
        :key="item.products.productId"
        @click.stop="getClick(item.products.productId)"
      >
        <RouterLink :to="`/detail/${item.products.productId}`">
          <img :src="item.productImages[0].imageUrl" alt="" />
          <p class="name">{{ item.products.name }}</p>
          <p class="price">{{ item.products.tags }}</p>
        </RouterLink>
      </li>
    </ul>
  </HomePanel>
</template>

<style scoped lang="scss">
.goods-list {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  gap: 40px;

  li {
    width: 306px;
    height: 406px;

    background: #f0f9f4;
    transition: all 0.5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

    img {
      width: 306px;
      height: 306px;
    }

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }

    .price {
      font-size: 14px;
      color: $priceColor;
    }
  }
}
</style>
